package com.itqf.factory;

import java.io.IOException;
import java.util.Properties;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/13
 * @Time: 上午9:58
 */
public class MyFactory {
    Properties properties = new Properties();

    public  MyFactory(){}
    public  MyFactory(String  config){
        try {
            properties.load(MyFactory.class.getResourceAsStream(config));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 根据name  获得对象
     * @return
     */
    public    Object  getBean(String  name){
        try {
            //usersDao=com.itqf.dao.impl.UserDaoImpl
            Object  classPath =  properties.get(name);
            if (classPath!=null){
                //com.itqf.dao.impl.UserDaoImpl
               Class clazz =  Class.forName(classPath+"");

               //创建对象
              return   clazz.newInstance();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;

    }



}
